package com.book.items.vistor;

import com.book.items.composite.AbstractProductItem;
import com.book.items.composite.ProductComposite;
import com.book.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @param
 * @author oyz
 * @version 1.0.4
 * @description: TODO
 * @date 2023/11/13 21:18
 */
@Component
public class AddItemVisitor implements ItemVisitor<AbstractProductItem>{

    @Autowired
    private RedisUtils redisUtils;

    @Override
    public AbstractProductItem visitor(AbstractProductItem productItem) {

        ProductComposite currentItems = (ProductComposite) redisUtils.get("items");
        ProductComposite addItems = (ProductComposite) productItem;
        // 如果新增的父节点为当前节点,则直接添加
        if(currentItems.getId() == addItems.getPid()){
            currentItems.addProductItem(addItems);
            return currentItems;
        }
        // 通过addChild方法进行遍历寻找新增类目的插入点
        addChild(addItems,currentItems);
        return currentItems;
    }

    private void addChild(ProductComposite addItems, ProductComposite currentItems) {


    }
}
